const state = {}

const formatJson = (filterVal, jsonData) => {
    return jsonData.map(v =>
        filterVal.map(j => {
            if (j === "timestamp") {
                return parseTime(v[j]);
            } else {
                return v[j];
            }
        })
    );
}
const mutations = {
    SET_EXPORT_EXCEL: (state, { tHeader, filterVal, exportExcelData }) => {

        import("@/vendor/Export2Excel").then(excel => {

            const data = formatJson(filterVal, exportExcelData);

            excel.export_json_to_excel({
                data,
                header: tHeader,
                filename: this.filename,
                bookType: this.bookType,
                autoWidth: this.autoWidth
            });
        });
    },
}

const actions = {
    setExportExcel({ commit }, { tHeader, filterVal, exportExcelData }) {
        commit('SET_EXPORT_EXCEL', { tHeader, filterVal, exportExcelData })
    },
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
